<template>
  <div class="app-container">
    <div class="head-container">
      <div >
        <el-form size="small" label-width="100px" v-formkey="{query:crud.toQuery}">
          <el-row >
            <el-col :xs="24" :sm="12" :md="8" :lg="6" :xl="6">
              <el-form-item label="业务日期">
                <div class="flex flex-row">
                  <el-date-picker
                    v-model="query.startTime"
                    align="right"
                    unlink-panels
                    class="fl1"
                    format="yyyy - MM - dd "
                    value-format="yyyy-MM-dd"
                    default-value
                    range-separator=""
                    placeholder="开始日期"
                  />
                  <el-date-picker
                    v-model="query.endTime"
                    align="right"
                    unlink-panels
                    class="fl1"
                    format="yyyy - MM - dd "
                    value-format="yyyy-MM-dd"
                    default-value
                    range-separator=""
                    placeholder="结束日期"
                  />
                </div>
              </el-form-item>
            </el-col>
            <el-col :xs="24" :sm="12" :md="8" :lg="6" :xl="6">
              <el-form-item label="编码">
                <el-input  v-model="query.code"></el-input>
              </el-form-item>
            </el-col>
            <el-col :xs="24" :sm="12" :md="8" :lg="6" :xl="6">
              <el-form-item label="供应商">
                <table-select
                  :tableColumns="
                  [
                  {prop:'code',label:'供应商编码',width: '100'},
                  {prop:'name',label:'供应商名称',width: '400'},
                  ]"
                  labelKey="name"
                  valueKey="id"
                  width="600"
                  :value.sync="query.customerIds"
                  placeholder="请选择客户"
                  url="api/dropDown/basCustomerList"
                ></table-select>
              </el-form-item>
            </el-col>
            <el-col :xs="24" :sm="12" :md="8" :lg="6" :xl="6">
              <el-form-item label="来源类型">
                <el-select
                  v-model="query.sourceType"
                  class="filter-item"
                  clearable
                  placeholder="请选择"
                  size="small"
                  style="width: 100%"
                  @change="crud.toQuery"
                >
                  <el-option
                    v-for="item in dict.t_buy_order_type"
                    :key="item.id"
                    :label="item.label"
                    :value="item.value"
                  />
                </el-select>
              </el-form-item>
            </el-col>
            <el-col :xs="24" :sm="12" :md="8" :lg="6" :xl="6">
              <el-form-item label="采购渠道">
                <el-select
                  v-model="query.buyChannel"
                  class="filter-item"
                  clearable
                  placeholder="请选择"
                  size="small"
                  style="width: 100%"
                  @change="crud.toQuery"
                >
                  <el-option
                    v-for="item in dict.t_buy_order_buy_channel"
                    :key="item.id"
                    :label="item.label"
                    :value="item.value"
                  />
                </el-select>
              </el-form-item>
            </el-col>
            <el-col :xs="24" :sm="12" :md="8" :lg="6" :xl="6">
              <el-form-item label="状态">
                <el-select
                  v-model="query.orderStatus"
                  class="filter-item"
                  clearable
                  placeholder="状态"
                  size="small"
                  style="width: 100%"
                  @change="crud.toQuery"
                >
                  <el-option
                    v-for="item in dict.common_order_status"
                    :key="item.id"
                    :label="item.label"
                    :value="item.value"
                  />
                </el-select>
              </el-form-item>
            </el-col>
            <el-col :xs="24" :sm="12" :md="8" :lg="6" :xl="6">
              <el-form-item label="备注">
                <el-input  v-model="query.remark"></el-input>
              </el-form-item>
            </el-col>
            <el-col :xs="24" :sm="12" :md="8" :lg="6" :xl="6">
              <el-form-item label="是否验收">
                <el-select
                  v-model="query.isAccept"
                  class="filter-item"
                  clearable
                  placeholder="请选择"
                  size="small"
                  style="width: 100%"
                  @change="crud.toQuery"
                >
                  <el-option
                    v-for="item in dict.common_yes_or_no"
                    :key="item.id"
                    :label="item.label"
                    :value="item.value"
                  />
                </el-select>
              </el-form-item>
            </el-col>
            <el-col :xs="24" :sm="12" :md="8" :lg="6" :xl="6">
              <el-form-item label="商品名称">
                <el-input v-model="query.goodsName" />
              </el-form-item>
            </el-col>

            <el-col :xs="24" :sm="12" :md="8" :lg="6" :xl="6">
              <el-form-item label="商品">
                <table-select
                  :tableColumns="[{prop:'goodsCode',label:'商品编码',width:'100'},{prop:'goodsName',label:'商品名称',width: '280'}]"
                  labelKey="goodsName"
                  valueKey="goodsId"
                  :value.sync="query.goodsIds"
                  placeholder="请选择商品"
                  url="/api/dropDown/basGoodsListForAdd"
                ></table-select>
              </el-form-item>
            </el-col>
            <el-col :xs="24" :sm="12" :md="8" :lg="6" :xl="6">
              <el-form-item label="添加人">
                <el-input  v-model="query.createUserName"></el-input>
              </el-form-item>
            </el-col>
          </el-row>
          <el-row>
            <el-col :xs="24" :sm="12" :md="8" :lg="6" :xl="6"  style="margin-bottom: 5px;margin-top: 5px">
              <rrOperation :crud="crud"/>
            </el-col>
          </el-row>
        </el-form>
      </div>
      <!--工具栏-->
      <crudOperation :permission="permission">
        <el-button
          slot="left"
          class="filter-item"
          size="mini"
          type="primary"
          @click="crud.toDetail('buyOrderDetail')"
          v-permission="permission.add"
        >
          新增
        </el-button>
        <el-button
          slot="left"
          class="filter-item"
          size="mini"
          type="success"
          :disabled="crud.selections.length !== 1"
          @click="crud.toDetail('buyOrderDetail',crud.selections[0].id)"
          v-permission="permission.edit"
        >修改
        </el-button>
        <el-button

          slot="right"
          class="filter-item"
          size="mini"
          type="success"
          :disabled="crud.selections.length !== 1  "
          :loading="crud.passLoading"
          @click="crud.enableOrDisable('INVALID')"
          v-permission="permission.invalid"
        >
          <!--        v-permission="permission.pass"-->
          作废
        </el-button>
        <el-button
          slot="right"
          class="filter-item"
          size="mini"
          type="info"
          :loading="crud.rejectLoading"
          :disabled="crud.selections.length !== 1 "
          @click="crud.enableOrDisable('RECOVER')"

        >
          <!--        v-permission="permission.reject"-->
          取消作废
        </el-button>
        <el-button
          slot="right"
          class="filter-item"
          size="mini"
          type="success"
          :loading="crud.passLoading"
          @click="crud.toAccept()"
          v-permission="permission.accept"
        >
          <!--        v-permission="permission.pass"-->
          验收
        </el-button>
        <el-button
          slot="right"
          class="filter-item"
          size="mini"
          type="info"
          :loading="crud.rejectLoading"
          @click="crud.toUnAccept()"
          v-permission="permission.accept"
        >
          <!--        v-permission="permission.reject"-->
          反验收
        </el-button>
        <el-button
          slot="right"
          class="filter-item"
          size="mini"
          @click="crud.toCopy()"
          v-permission="permission.copy"
        >
          复制
        </el-button>
        <el-button
          slot="left"
          class="filter-item"
          size="mini"
          type="success"
          :disabled="crud.selections.length !== 1"
          @click="crud.toPrint('buyOrder',crud.selections[0].id)"
          v-permission="permission.print"
        >打印
        </el-button>
      </crudOperation>
      <vue-context-menu :contextMenuData="contextMenuData"
                        @tableConfig="tableConfig"
                        @deletedata="deletedata"></vue-context-menu>
      <el-dialog title="表格配置"
                 :visible.sync="tableConfigShow"
                 width="60%">
        <j-table-column-config :columns.sync="crud.header" @tabSave="tabSave" @pit="pit" />
      </el-dialog>
      <!--表格渲染-->
      <el-table ref="table"
                border
                v-if="isShowTable"
                @header-dragend="changeColWidth"
                @contextmenu.native="showMenu"
                :height="tableHeight"
                show-summary
                @cell-dblclick="row=>crud.toEdit(row)"
                v-loading="crud.loading"
                :data="crud.data"
                size="small"
                style="width: 100%;"
                :summary-method="crud.sumRow"
                @row-click="crud.selectRow"
                :row-style="crud.rowClass"
                :row-class-name="crud.tableRowClassName"
                @selection-change="crud.selectionChangeHandler"
                @row-dblclick="row=>setQuery(row.id)">
        <el-table-column :render-header="crud.renderHeader" type="selection" width="60" />
        <el-table-column :render-header="crud.renderHeader" type="index" width="60" label="序号"/>
        <el-table-column

          v-if="item.visible"
          v-for="(item, index) in crud.header"
          :key="`col_${index}`"
          :prop="item.prop"
          :label="columnLabel(item)"
          :width="item.width + 'px'"
          :data-porp='item.prop'
          @contextmenu.native="showMenu"
          @header-dragend="changeColWidth"
        >
          <!-- 自定义渲染模版 -->
          <template slot-scope="scope">
            <!-- 当列key为 sort 时，渲染一个手柄icon -->
            <template>
              <span :class="{'red':(scope.row[`type`] === 2),'blue':(item.orderStatus==='INVALID')}" v-if="item.type == 1" style="margin-left: 10px">
                  {{scope.row[`${item.prop}`]}}
              </span>
              <span :class="{'red':(scope.row[`type`] === 2),'blue':(item.orderStatus==='INVALID')}" v-else-if="item.type == 2" style="margin-left: 10px">{{ parseTime(scope.row[`${item.prop}`])}}</span>
              <span :class="{'red':(scope.row[`type`] === 2),'blue':(item.orderStatus==='INVALID')}" v-else-if="item.type == 3" style="margin-left: 10px">
                  {{ getDict(`this.dict.label.${item.dictionary}["${scope.row[item.prop]}"]`) }}
              </span>
            </template>
          </template>
        </el-table-column>

<!--        <el-table-column :render-header="crud.renderHeader" v-if="columns.visible('code')" prop="code" label="编号" />-->
<!--        <el-table-column :render-header="crud.renderHeader" v-if="columns.visible('busDate')" prop="busDate" label="业务日期" >-->
<!--          <template slot-scope="scope">-->
<!--            <span>{{ parseDate(scope.row.busDate) }}</span>-->
<!--          </template>-->
<!--        </el-table-column>-->
<!--        <el-table-column :render-header="crud.renderHeader" v-if="columns.visible('customerTypeName')" prop="customerTypeName" label="供应商分类"  />-->
<!--        <el-table-column :render-header="crud.renderHeader" v-if="columns.visible('customerAreaName')" prop="customerAreaName" label="供应商区域" />-->
<!--        <el-table-column :render-header="crud.renderHeader" v-if="columns.visible('customerCode')" prop="customerCode" label="供应商编码"  />-->
<!--        <el-table-column :render-header="crud.renderHeader" v-if="columns.visible('customerName')" prop="customerName" label="供应商名称" />-->
<!--        <el-table-column :render-header="crud.renderHeader" v-if="columns.visible('deptName')" prop="deptName" label="采购部门" />-->
<!--        <el-table-column :render-header="crud.renderHeader" v-if="columns.visible('userName')" prop="userName" label="采购员" />-->
<!--        <el-table-column :render-header="crud.renderHeader" v-if="columns.visible('buyChannel')" prop="buyChannel" label="采购渠道" >-->
<!--          <template slot-scope="scope">-->
<!--            <el-tag>{{ dictName(dict.t_buy_order_buy_channel,scope.row.buyChannel)  }}</el-tag>-->
<!--          </template>-->
<!--        </el-table-column>-->
<!--&lt;!&ndash;        <el-table-column :render-header="crud.renderHeader" v-if="columns.visible('customerTypeName')" prop="customerTypeName" label="供应商分类"  />&ndash;&gt;-->
<!--&lt;!&ndash;        <el-table-column :render-header="crud.renderHeader" v-if="columns.visible('customerAreaName')" prop="customerAreaName" label="供应商区域"  />&ndash;&gt;-->
<!--        <el-table-column :render-header="crud.renderHeader" v-if="columns.visible('warehouseName')" prop="warehouseName" label="仓库" />-->
<!--        <el-table-column :render-header="crud.renderHeader" v-if="columns.visible('type')" prop="type" label="采购单类型" >-->
<!--          <template slot-scope="scope">-->
<!--            <span>{{ dictName(dict.t_buy_order_type,scope.row.type)  }}</span>-->
<!--          </template>-->
<!--        </el-table-column>-->
<!--&lt;!&ndash;        <el-table-column :render-header="crud.renderHeader" v-if="columns.visible('sourceType')" prop="sourceType" label="来源类型" >&ndash;&gt;-->
<!--&lt;!&ndash;          <template slot-scope="scope">&ndash;&gt;-->
<!--&lt;!&ndash;            <span>{{ dictName(dict.t_buy_order_source_type,scope.row.sourceType)  }}</span>&ndash;&gt;-->
<!--&lt;!&ndash;          </template>&ndash;&gt;-->
<!--&lt;!&ndash;        </el-table-column>&ndash;&gt;-->
<!--        <el-table-column :render-header="crud.renderHeader" v-if="columns.visible('sourceCode')" prop="sourceCode" label="来源编号" />-->
<!--        <el-table-column :render-header="crud.renderHeader" v-if="columns.visible('boxCount')" prop="boxCount" label="箱数" />-->
<!--        <el-table-column :render-header="crud.renderHeader" v-if="columns.visible('taxAmount')" prop="taxAmount" label="含税金额" />-->
<!--        <el-table-column :render-header="crud.renderHeader" v-if="columns.visible('noTaxAmount')" prop="noTaxAmount" label="未税金额" />-->
<!--        <el-table-column :render-header="crud.renderHeader" v-if="columns.visible('tax')" prop="tax" label="税额" />-->
<!--        <el-table-column :render-header="crud.renderHeader" v-if="columns.visible('discountAmount')" prop="discountAmount" label="折扣金额" />-->
<!--&lt;!&ndash;        <el-table-column :render-header="crud.renderHeader" v-if="columns.visible('isPrint')" prop="isPrint" label="打印状态" >&ndash;&gt;-->
<!--&lt;!&ndash;          <template slot-scope="scope">&ndash;&gt;-->
<!--&lt;!&ndash;            <el-tag>{{ dictName(dict.t_print_config_type,scope.row.isPrint)  }}</el-tag>&ndash;&gt;-->
<!--&lt;!&ndash;          </template>&ndash;&gt;-->
<!--&lt;!&ndash;        </el-table-column>&ndash;&gt;-->
<!--        <el-table-column :render-header="crud.renderHeader" v-if="columns.visible('printCount')" prop="printCount" label="打印次数" />-->
<!--        <el-table-column :render-header="crud.renderHeader" v-if="columns.visible('cancelStatus')" prop="cancelStatus" label="核销状态" >-->
<!--          <template slot-scope="scope">-->
<!--            <el-tag>{{ dictName(dict.common_cancel_status,scope.row.cancelStatus)  }}</el-tag>-->
<!--          </template>-->
<!--        </el-table-column>-->
<!--        <el-table-column :render-header="crud.renderHeader" v-if="columns.visible('drawDate')" prop="drawDate" label="抽单日期" >-->
<!--          <template slot-scope="scope">-->
<!--            <span>{{ parseDate(scope.row.drawDate) }}</span>-->
<!--          </template>-->
<!--        </el-table-column>-->
<!--        <el-table-column :render-header="crud.renderHeader" v-if="columns.visible('isDraw')" prop="isDraw" label="是否抽单" >-->
<!--          <template slot-scope="scope">-->
<!--            <el-tag>{{ dictName(dict.common_yes_or_no,scope.row.isDraw)  }}</el-tag>-->
<!--          </template>-->
<!--        </el-table-column>-->
<!--        <el-table-column :render-header="crud.renderHeader" v-if="columns.visible('drawUserName')" prop="drawUserName" label="抽单人" ></el-table-column>-->
<!--        <el-table-column :render-header="crud.renderHeader" v-if="columns.visible('isAccept')" prop="isAccept" label="是否验收" >-->
<!--          <template slot-scope="scope">-->
<!--            <el-tag>{{ dictName(dict.common_yes_or_no,scope.row.isAccept)  }}</el-tag>-->
<!--          </template>-->
<!--        </el-table-column>-->
<!--        <el-table-column :render-header="crud.renderHeader" v-if="columns.visible('count')" prop="count" label="商品条数" />-->
<!--        <el-table-column :render-header="crud.renderHeader" v-if="columns.visible('acceptUserName')" prop="acceptUserName" label="验收人" />-->
<!--        <el-table-column :render-header="crud.renderHeader" v-if="columns.visible('cancelUserName')" prop="cancelUserName" label="核销人" />-->
<!--        <el-table-column :render-header="crud.renderHeader" v-if="columns.visible('unCancelAmount')" prop="unCancelAmount" label="未核销金额" />-->
<!--        <el-table-column :render-header="crud.renderHeader" v-if="columns.visible('isAppend')" prop="isAppend" label="是否追加" >-->
<!--          <template slot-scope="scope">-->
<!--            <span>{{ dictName(dict.common_yes_or_no,scope.row.isAppend) }}</span>-->
<!--          </template>-->
<!--        </el-table-column>-->
<!--        <el-table-column :render-header="crud.renderHeader" v-if="columns.visible('acceptBoxCount')" prop="acceptBoxCount" label="验收箱数" />-->
<!--        <el-table-column :render-header="crud.renderHeader" v-if="columns.visible('acceptTaxAmount')" prop="acceptTaxAmount" label="验收含税金额"  />-->
<!--        <el-table-column :render-header="crud.renderHeader" v-if="columns.visible('acceptNoTaxAmount')" prop="acceptNoTaxAmount" label="验收未税金额"  />-->
<!--        <el-table-column :render-header="crud.renderHeader" v-if="columns.visible('acceptTax')" prop="acceptTax" label="验收税额" />-->
<!--        <el-table-column :render-header="crud.renderHeader" v-if="columns.visible('acceptUserName')" prop="acceptUserName" label="验收人" />-->
<!--        <el-table-column :render-header="crud.renderHeader" v-if="columns.visible('acceptDate')" prop="acceptDate" label="验收时间" >-->
<!--          <template slot-scope="scope">-->
<!--            <span>{{ parseTime(scope.row.acceptDate) }}</span>-->
<!--          </template>-->
<!--        </el-table-column>-->
<!--        <el-table-column :render-header="crud.renderHeader" v-if="columns.visible('orderRemark')" prop="orderRemark" label="单据说明" />-->
<!--        <el-table-column :render-header="crud.renderHeader" v-if="columns.visible('volume')" prop="volume" label="总体积" />-->
<!--        <el-table-column :render-header="crud.renderHeader" v-if="columns.visible('weight')" prop="weight" label="总重量" />-->
<!--        <el-table-column :render-header="crud.renderHeader" v-if="columns.visible('remark')" prop="remark" label="备注" />-->

<!--        <el-table-column :render-header="crud.renderHeader" v-if="columns.visible('orderStatus')" align="center" label="状态" prop="orderStatus">-->
<!--          <template slot-scope="scope">-->
<!--            <el-tag>{{ dictName(dict.common_order_status,scope.row.orderStatus)  }}</el-tag>-->
<!--          </template>-->
<!--        </el-table-column>-->
<!--        <el-table-column :render-header="crud.renderHeader" v-if="columns.visible('createUserName')" prop="createUserName" label="添加人" />-->
<!--        <el-table-column :render-header="crud.renderHeader" v-if="columns.visible('createTime')" prop="createTime" label="添加时间">-->
<!--          <template slot-scope="scope">-->
<!--            <span>{{ parseTime(scope.row.createTime) }}</span>-->
<!--          </template>-->
<!--        </el-table-column>-->
<!--        <el-table-column :render-header="crud.renderHeader" v-if="columns.visible('updateUserName')" prop="updateUserName" label="修改人" />-->
<!--        <el-table-column :render-header="crud.renderHeader" v-if="columns.visible('updateTime')" prop="updateTime" label="修改时间">-->
<!--          <template slot-scope="scope">-->
<!--            <span>{{ parseTime(scope.row.updateTime) }}</span>-->
<!--          </template>-->
<!--        </el-table-column>-->
<!--        <el-table-column :render-header="crud.renderHeader" v-if="columns.visible('auditUserName')" prop="auditUserName" label="审核人" />-->
<!--        <el-table-column :render-header="crud.renderHeader" v-if="columns.visible('auditTime')" prop="auditTime" label="审核时间">-->
<!--          <template slot-scope="scope">-->
<!--            <span>{{ parseTime(scope.row.auditTime) }}</span>-->
<!--          </template>-->
<!--        </el-table-column>-->
<!--        <el-table-column :render-header="crud.renderHeader" v-if="columns.visible('cancelUserName')" prop="cancelUserName" label="核销人" />-->
<!--        <el-table-column :render-header="crud.renderHeader" v-if="columns.visible('cancelDate')" prop="cancelDate" label="核销时间">-->
<!--          <template slot-scope="scope">-->
<!--            <span>{{ parseTime(scope.row.cancelDate) }}</span>-->
<!--          </template>-->
<!--        </el-table-column>-->
<!--        <el-table-column :render-header="crud.renderHeader" v-if="columns.visible('closeUserName')" prop="closeUserName" label="关闭人" />-->
<!--        <el-table-column :render-header="crud.renderHeader" v-if="columns.visible('closeTime')" prop="closeTime" label="关闭时间">-->
<!--          <template slot-scope="scope">-->
<!--            <span>{{ parseTime(scope.row.closeTime) }}</span>-->
<!--          </template>-->
<!--        </el-table-column>-->
<!--        <el-table-column :render-header="crud.renderHeader" v-permission="['admin','buyOrderDetail:edit','buyOrderDetail:del']" label="操作" width="150px" fixed="right" align="center">-->
<!--          <template slot-scope="scope">-->
<!--            <udOperation-->
<!--              :data="scope.row"-->
<!--              :permission="permission"-->
<!--            />-->
<!--          </template>-->
<!--        </el-table-column>-->
      </el-table>
      <!--分页组件-->
      <pagination />
      <el-dialog  title="打印预览"
                  destroy-on-close
                  v-dialogDrag
                  close-on-press-escape
                  :visible.sync="showPdf" append-to-body width="50vw">
        <j-pdf :src="pdfSrc" ></j-pdf>
      </el-dialog>
      <el-dialog  title="搜索"
                  :before-close="handleClose"
                  destroy-on-close
                  v-dialogDrag
                  close-on-press-escape
                  width="80%"
                  :visible.sync="!crud.props.searchToggle" >
        <el-form size="small" label-width="100px">
          <el-row :gutter="10">
            <el-col :xs="24" :sm="12" :md="8" :lg="6" :xl="6">
              <el-form-item label="业务日期">
                <el-date-picker
                  v-model="query.dataExtent"
                  type="daterange"
                  @change="getValue()"
                  align="right"
                  unlink-panels
                  style="width: 100%"
                  format="yyyy - MM - dd "
                  value-format="yyyy-MM-dd"
                  default-value
                  range-separator=""
                  start-placeholder="开始日期"
                  end-placeholder="结束日期"
                  :picker-options="pickerOptions">
                </el-date-picker>
              </el-form-item>
            </el-col>
            <el-col :xs="24" :sm="12" :md="8" :lg="6" :xl="6">
              <el-form-item label="编码">
                <el-input  v-model="query.code"></el-input>
              </el-form-item>
            </el-col>
            <el-col :xs="24" :sm="12" :md="8" :lg="6" :xl="6">
              <el-form-item label="状态">
                <el-select
                  v-model="query.orderStatus"
                  class="filter-item"
                  clearable
                  placeholder="状态"
                  size="small"
                  style="width: 100%"
                  @change="crud.toQuery"
                >
                  <el-option
                    v-for="item in dict.common_order_status"
                    :key="item.id"
                    :label="item.label"
                    :value="item.value"
                  />
                </el-select>
              </el-form-item>
            </el-col>
            <el-col :xs="24" :sm="12" :md="8" :lg="6" :xl="6">
              <el-form-item label="供应商">
                <zSelect :value.sync="query.customerId" url="api/dropDown/basCustomerList" :params="{businessAttr:'3'}"
                         style="width:  100%"/>
              </el-form-item>
            </el-col>
          </el-row>
          <el-row :gutter="10">
            <el-col :xs="24" :sm="12" :md="8" :lg="6" :xl="6">
              <el-form-item label="仓库">
                <zSelect :value.sync="query.warehouseId" url="api/dropDown/basWarehouseList" />
              </el-form-item>
            </el-col>
            <el-col :xs="24" :sm="12" :md="8" :lg="6" :xl="6">
              <el-form-item label="打印状态">
                <el-select
                  v-model="query.isPrint"
                  class="filter-item"
                  clearable
                  placeholder="打印状态"
                  size="small"
                  style="width: 100%"
                  @change="crud.toQuery"
                >
                  <el-option
                    v-for="item in dict.common_yes_or_no"
                    :key="item.id"
                    :label="item.label"
                    :value="item.value"
                  />
                </el-select>
              </el-form-item>
            </el-col>
            <el-col :xs="24" :sm="12" :md="8" :lg="6" :xl="6">
              <el-form-item label="核销状态">
                <el-select
                  v-model="query.cancelStatus"
                  class="filter-item"
                  clearable
                  placeholder="请选择"
                  size="small"
                  style="width: 100%"
                  @change="crud.toQuery"
                >
                  <el-option
                    v-for="item in dict.common_cancel_status"
                    :key="item.id"
                    :label="item.label"
                    :value="item.value"
                  />
                </el-select>
              </el-form-item>
            </el-col>
            <el-col :xs="24" :sm="12" :md="8" :lg="6" :xl="6">
              <el-form-item label="是否抽单">
                <el-select
                  v-model="query.isDraw"
                  class="filter-item"
                  clearable
                  placeholder="请选择"
                  size="small"
                  style="width: 100%"
                  @change="crud.toQuery"
                >
                  <el-option
                    v-for="item in dict.common_yes_or_no"
                    :key="item.id"
                    :label="item.label"
                    :value="item.value"
                  />
                </el-select>
              </el-form-item>
            </el-col>
          </el-row>
          <el-row :gutter="10">
            <el-col :xs="24" :sm="12" :md="8" :lg="6" :xl="6">
              <el-form-item label="是否验收">
                <el-select
                  v-model="query.isAccept"
                  class="filter-item"
                  clearable
                  placeholder="请选择"
                  size="small"
                  style="width: 100%"
                  @change="crud.toQuery"
                >
                  <el-option
                    v-for="item in dict.common_yes_or_no"
                    :key="item.id"
                    :label="item.label"
                    :value="item.value"
                  />
                </el-select>
              </el-form-item>
            </el-col>
            <el-col :xs="24" :sm="12" :md="8" :lg="6" :xl="6">
              <el-form-item label="采购渠道">
                <el-select
                  v-model="query.buyChannel"
                  class="filter-item"
                  clearable
                  placeholder="请选择"
                  size="small"
                  style="width: 100%"
                  @change="crud.toQuery"
                >
                  <el-option
                    v-for="item in dict.t_buy_order_buy_channel"
                    :key="item.id"
                    :label="item.label"
                    :value="item.value"
                  />
                </el-select>
              </el-form-item>
            </el-col>
            <el-col :xs="24" :sm="12" :md="8" :lg="6" :xl="6">
              <el-form-item label="采购单类型">
                <el-select
                  v-model="query.type"
                  class="filter-item"
                  clearable
                  placeholder="请选择"
                  size="small"
                  style="width: 100%"
                  @change="crud.toQuery"
                >
                  <el-option
                    v-for="item in dict.t_buy_order_type"
                    :key="item.id"
                    :label="item.label"
                    :value="item.value"
                  />
                </el-select>
              </el-form-item>
            </el-col>
            <el-col :xs="24" :sm="12" :md="8" :lg="6" :xl="6">
              <el-form-item label="供应商分类">
                <JtgTree
                  v-model="query.customerTypeId"
                  :initValue="query.customerTypeName"
                  :keyword="query.customerTypeName"
                  url="basCustomerTypeTree"
                />
                <!--                <zSelect :value.sync="query.basCustomerType" url="api/dropDown/basCustomerTypeList"-->
                <!--                         style="width:  100%"/>-->
              </el-form-item>
            </el-col>
          </el-row>
          <el-row :gutter="10">
            <el-col :xs="24" :sm="12" :md="8" :lg="6" :xl="6">
              <el-form-item label="供应商区域">
                <JtgTree
                  v-model="query.customerAreaId"
                  :initValue="query.customerAreaName"
                  :keyword="query.customerAreaId"
                  url="basCustomerAreaTree"
                />
                <!--                <zSelect :value.sync="query.basCustomerArea" url="api/dropDown/basCustomerAreaList"-->
                <!--                         style="width:  100%"/>-->
              </el-form-item>
            </el-col>
            <el-col :xs="24" :sm="12" :md="8" :lg="5" :xl="5" >
              <el-form-item label="采购部门" >
                <JtgTree
                  v-model="query.deptId"
                  :initValue="query.deptName"
                  :keyword="query.deptId"
                  url="childSysDeptList"
                />
                <!--                <zSelect :value.sync="query.deptId"   url="api/dropDown/childSysDeptList"-->
                <!--                         style="width:  100%"/>-->
              </el-form-item>
            </el-col>
            <el-col :xs="24" :sm="12" :md="8" :lg="6" :xl="6">
              <el-form-item label="采购人">
                <zSelect :value.sync="query.userId"   url="api/dropDown/sysUserList"
                         style="width:  100%"/>
              </el-form-item>
            </el-col>
            <el-col :xs="24" :sm="12" :md="8" :lg="6" :xl="6">
              <el-form-item label="单据类型">
                <el-select v-model="query.type" style="width:  100%"  class="edit-input" placeholder="请选择单据类型" >
                  <el-option
                    v-for="(item,index) in dict.t_buy_order_type"
                    :key="index"
                    v-if="item.seq>0"
                    :label="item.label"
                    :value="item.value"
                  />
                </el-select>
              </el-form-item>
            </el-col>
<!--            <el-col :xs="24" :sm="12" :md="8" :lg="6" :xl="6">-->
<!--              <el-form-item label="来源类型">-->
<!--                <el-select-->
<!--                  v-model="query.sourceType"-->
<!--                  class="filter-item"-->
<!--                  clearable-->
<!--                  placeholder="请选择"-->
<!--                  size="small"-->
<!--                  style="width: 100%"-->
<!--                  @change="crud.toQuery"-->
<!--                >-->
<!--                  <el-option-->
<!--                    v-for="item in dict.t_buy_order_type"-->
<!--                    :key="item.id"-->
<!--                    :label="item.label"-->
<!--                    :value="item.value"-->
<!--                  />-->
<!--                </el-select>-->
<!--              </el-form-item>-->
<!--            </el-col>-->
          </el-row>
          <el-row :gutter="10">
            <el-col :xs="24" :sm="12" :md="8" :lg="6" :xl="6">
              <el-form-item label="来源单据编号">
                <el-input  v-model="query.sourceCode"></el-input>
              </el-form-item>
            </el-col>
            <el-col :xs="24" :sm="12" :md="8" :lg="6" :xl="6">
              <el-form-item label="备注">
                <el-input  v-model="query.remark"></el-input>
              </el-form-item>
            </el-col>
            <el-col :xs="24" :sm="12" :md="8" :lg="6" :xl="6">
              <el-form-item label="添加人">
                <el-input  v-model="query.createUserName"></el-input>
              </el-form-item>
            </el-col>
          </el-row>
          <el-row :gutter="10" style="text-align: center">
            <el-button class="filter-item"  size="mini" type="primary" @click="toQuery">搜索</el-button>
            <el-button class="filter-item" plain   size="mini" type="primary"
                       @click="resetQuery()">重置</el-button>
<!--            <el-col :xs="24" :sm="12" :md="8" :lg="6" :xl="6">-->
<!--              <rrOperation :crud="crud"/>-->
<!--            </el-col>-->
          </el-row>
        </el-form>
      </el-dialog>

    </div>
  </div>
</template>

<script>
import crudBuyOrderDetail from '@/api/erp/buyOrder'
import CRUD, { presenter, header, form, crud } from '@crud/crud'
import rrOperation from '@crud/RR.operation'
import crudOperation from '@crud/CRUD.operation'
import udOperation from '@crud/UD.operation'
import pagination from '@crud/Pagination'
import JtgTree from "@/components/Tree/JtgTreePlus";
import {tablemixins} from "@/mixins/tablemixins";
import jTableColumnConfig from "@/components/jTableColumnConfig/jTableColumnConfig";
import { publicListKey } from "@/utils/key";
import {getBuyOrderPreviousNextPageIdList} from "../../../api/erp/buyOrder";
// crud交由presenter持有
const defaultCrud = CRUD({ title: '采购单', name:'buyOrder',url: 'api/buyOrder', optShow: {
    add: false,
    edit: false,
    del: true,
    download: true,
    leadingIn: true,
    enable: false,
    downloadDetail: true,
    disable: false,
    pass: true,
    reject: true
  }, query:{
    startTime: null,endDate:null,dataExtent:null,
  },  sort: 'id,desc', crudMethod: { ...crudBuyOrderDetail }})
const defaultForm = { id: null, orderId: null, sourceDetailId: null, goodsId: null, goodsCode: null, goodsName: null, barcode: null, boxBarcode: null, helpSign: null, model: null, goodsBrandId: null, goodsBrandCode: null, goodsBrandName: null, goodsTypeId: null, goodsTypeCode: null, goodsTypeName: null, goodsTagId: null, goodsTagCode: null, goodsTagName: null, taxId: null, taxCode: null, taxName: null, taxRate: null, warehouseId: null, warehouseCode: null, warehouseName: null, locationId: null, locationCode: null, locationName: null, storehouseId: null, storehouseCode: null, storehouseName: null, batchNo: null, producedDate: null, deadlineDate: null, boxUnitId: null, boxUnitCode: null, boxUnitName: null, boxUnitCount: null, boxNum: null, mainUnitId: null, mainUnitCode: null, mainUnitName: null, mainUnitCount: null, mainNum: null, usableNum: null, usableBoxNum: null, goodsCount: null, boxCount: null, taxPrice: null, noTaxPrice: null, taxBoxPrice: null, noTaxBoxPrice: null, taxAmount: null, noTaxAmount: null, tax: null, discountRate: null, discountAmount: null, oldTaxPrice: null, oldNoTaxPrice: null, oldTaxBoxPrice: null, oldNoTaxBoxPrice: null, oldTaxAmount: null, oldNoTaxAmount: null, oldTax: null, acceptCount: null, acceptBoxCount: null, acceptTaxAmount: null, acceptNoTaxAmount: null, acceptTax: null, appendGoodsCount: null, appendBoxCount: null, unAppendGoodsCount: null, unAppendBoxCount: null, seq: null, remark: null, createUserId: null, createUserCode: null, createUserName: null, createTime: null, updateUserId: null, updateUserCode: null, updateUserName: null, updateTime: null }
export default {
  name: 'BuyOrder',
  components: { pagination, crudOperation, rrOperation, udOperation,JtgTree, jTableColumnConfig },
  mixins: [presenter(defaultCrud), header(), form(defaultForm), crud(),tablemixins,publicListKey],
  dicts: ['t_buy_order_source_type',
    't_buy_order_source_type',
    't_bas_customer_is_contact',
    'common_order_status',
    't_print_config_type',
    't_buy_order_buy_channel',
    'common_yes_or_no',
    'common_cancel_status','t_buy_order_type'],
  data() {
    return {
      pickerOptions: {
        shortcuts: [{
          text: '最近一周',
          onClick(picker) {
            const end = new Date();
            const start = new Date();
            start.setTime(start.getTime() - 3600 * 1000 * 24 * 7);
            picker.$emit('pick', [start, end]);
          }
        }, {
          text: '最近一个月',
          onClick(picker) {
            const end = new Date();
            const start = new Date();
            start.setTime(start.getTime() - 3600 * 1000 * 24 * 30);
            picker.$emit('pick', [start, end]);
          }
        }, {
          text: '最近三个月',
          onClick(picker) {
            const end = new Date();
            const start = new Date();
            start.setTime(start.getTime() - 3600 * 1000 * 24 * 90);
            picker.$emit('pick', [start, end]);
          }
        }]
      },
      permission: {
        add: ['admin', 'buyOrder:add'],
        edit: ['admin', 'buyOrder:edit'],
        del: ['admin', 'buyOrder:del'],
        import: ['admin', 'buyOrder:import'],
        export: ['admin', 'buyOrder:export'],
        copy: ['admin', 'buyOrder:copy'],
        upload: ['admin', 'buyOrder:upload'],
        download: ['admin', 'buyOrder:download'],
        pass: ['admin', 'buyOrder:pass'],
        reject: ['admin', 'buyOrder:reject'],
        closed: ['admin', 'buyOrder:closed'],
        invalid: ['admin', 'buyOrder:invalid'],
        stop: ['admin', 'buyOrder:stop'],
        recover: ['admin', 'buyOrder:recover'],
        print: ['admin', 'buyOrder:print'],
        addDetail: ['admin', 'buyOrder:addDetail'],
        batchAddDetail: ['admin', 'buyOrder:batchAddDetail'],
        accept: ['admin', 'buyOrder:accept'],
      },
      red:['acceptBoxCount','goodsCount','boxCount','boxCount','cancelAmount','unCancelAmount','taxAmount','noTaxAmount','tax','discountAmount',
        'oldTaxAmount','oldNoTaxAmount','oldTax','acceptTaxAmount','acceptNoTaxAmount','acceptTax'],
      // red:['acceptBoxCount','goodsCount','boxCount','boxCount','taxAmount','noTaxAmount','discountAmount','acceptTaxAmount','acceptNoTaxAmount',],
      rules: {
        orderId: [
          { required: true, message: '单据id不能为空', trigger: 'blur' }
        ],
        goodsId: [
          { required: true, message: '商品id不能为空', trigger: 'blur' }
        ]
      },
      tableHeight: 0
    }
  },
  created() {
    this.setTableHeight()
  },
  mounted() {
    let _this = this
    window.onresize = () => {
      return (() => {
        _this.setTableHeight()
      })();
    };
    // this.$refs.table.bodyWrapper.style.transform = 'translate(100)'
    // console.log(this.$refs.table.bodyWrapper)

  },
  watch: {
    'crud.data':{
      handler(n,o){
        if (!this.crud.data[0].isUpdate){
          this.crud.data[0].isUpdate=true
        for (let i in this.crud.data) {
          for (let key in this.crud.data[i]) {
            if (this.red.includes(key) && this.crud.data[i].type === 2) {
              this.crud.data[i][key] = Number(this.crud.data[i][key]) * -1
            }
          }
        }
        }
      },
      deep:true
    }
  },
  methods: {
    toQuery(){
      this.crud.props.searchToggle = !this.crud.props.searchToggle
      this.crud.toQuery()
    },
    setQuery(id){
      getBuyOrderPreviousNextPageIdList({...this.query,id,...this.crud.page,sort:this.query.sort || this.crud.sort}).then(res=>{
        const idDate = Date.now().toString()
        sessionStorage.setItem(idDate,JSON.stringify(res.data))
        this.$router.push({ path:`buyOrderDetail/${id}?idDate=${idDate}`})
      })
    },
    setTableHeight(){
      const ratio =this.getRatio() / 100
      this.tableHeight = (window.screen.height - (200*ratio)) / ratio
    },
    getRatio() {
      var ratio = 0;
      var screen = window.screen;
      var ua = navigator.userAgent.toLowerCase();

      if (window.devicePixelRatio !== undefined) {
        ratio = window.devicePixelRatio;
      } else if (~ua.indexOf('msie')) {
        if (screen.deviceXDPI && screen.logicalXDPI) {
          ratio = screen.deviceXDPI / screen.logicalXDPI;
        }

      } else if (window.outerWidth !== undefined && window.innerWidth !== undefined) {
        ratio = window.outerWidth / window.innerWidth;
      }

      if (ratio) {
        ratio = Math.round(ratio * 100);
      }
      return ratio;
    },
    // toQuery(){
    //   this.crud.props.searchToggle = !this.crud.props.searchToggle
    //   this.crud.toQuery()
    // },
    handleClose(){
      this.crud.props.searchToggle = !this.crud.props.searchToggle
    },
    resetQuery(){
      this.query.customerIds = null
      this.crud.resetQuery()
    },
    // 获取数据前设置好接口地址
    [CRUD.HOOK.beforeRefresh]() {
      return true
    }, // 新增与编辑前做的操作
    [CRUD.HOOK.afterToCU](crud, form) {
    },
    getValue(e){
      this.query.startTime =this.query.dataExtent[0]
      this.query.endTime =this.query.dataExtent[1]
    },
  }
}
</script>

<style lang="scss" scoped>
  .table-img {
    display: inline-block;
    text-align: center;
    background: #ccc;
    color: #fff;
    white-space: nowrap;
    position: relative;
    overflow: hidden;
    vertical-align: middle;
    width: 32px;
    height: 32px;
    line-height: 32px;
  }
  .red{
    color: red;
  }
  .blue{
  *{
    color: blue !important;
  }
  }
</style>
